package redisData

import (
	"cybertwin/pb/trustEva"
	"strconv"

	"github.com/sirupsen/logrus"
)

func MapToTrustEvaRequest(m map[string]string, ctid string, ueName string) (req *trustEva.TrustEvaRequest, err error) {
	normalCount, err := strconv.Atoi(m["normalCount"])
	if err != nil {
		logrus.Errorf("[GetTrustScore]-normalCount数值获取异常, err=%s", err)
		return nil, err
	}
	sensiCount, err := strconv.Atoi(m["sensiCount"])
	if err != nil {
		logrus.Errorf("[GetTrustScore]-sensiCount数值获取异常, err=%s", err)
		return nil, err
	}
	illegalCount, err := strconv.Atoi(m["illegalCount"])
	if err != nil {
		logrus.Errorf("[GetTrustScore]-illegalCount数值获取异常, err=%s", err)
		return nil, err
	}
	authCount, err := strconv.Atoi(m["authCount"])
	if err != nil {
		logrus.Errorf("[GetTrustScore]-authCount数值获取异常, err=%s", err)
		return nil, err
	}
	activeDevice, err := strconv.ParseBool(m["activeDevice"])
	if err != nil {
		logrus.Errorf("[GetTrustScore]-activeDevice数值获取异常, err=%s", err)
		return nil, err
	}
	activeZone, err := strconv.ParseBool(m["activeZone"])
	if err != nil {
		logrus.Errorf("[GetTrustScore]-activeZone数值获取异常, err=%s", err)
		return nil, err
	}
	req = &trustEva.TrustEvaRequest{
		MsgId:          "001",
		UeName:         ueName,
		CybertwinId:    ctid,
		NormalCount:    int32(normalCount),
		SensitiveCount: int32(sensiCount),
		AuthCount:      int32(authCount),
		IllegalCount:   int32(illegalCount),
		ActiveDevice:   activeDevice,
		ActiveZone:     activeZone,
	}
	return
}
